#include <stdio.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrMorphoDistance.h>
#include "../macro.h"

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_distance types
/////////////////////////////////////////////////////////////////////////
#define tstDistance(dtype)						\
									\
  dtype rawsrc[]={  0,  0,  0,255,255,255,255,255,  0,  0,		\
		    0,  0,  0,255,255,255,255,255,  0,  0,		\
		    0,  0,  0,255,255,255,255,255,  0,  0,		\
		    0,  0,  0,255,255,255,255,255,  0,  0,		\
		    0,  0,  0,255,255,255,255,255,  0,  0,		\
		    0,  0,  0,255,255,255,255,255,  0,  0,		\
		    255,255,  0,  0,  0,  0,  0,  0,  0,  0,		\
		    255,255,  0,  0,  0,  0,  0,  0,  0,  0};		\
									\
  dtype rawref[]={  0,  0,  0,  1,  2,  3,  2,  1,  0,  0,		\
		    0,  0,  0,  1,  2,  3,  2,  1,  0,  0,		\
		    0,  0,  0,  1,  2,  3,  2,  1,  0,  0,		\
		    0,  0,  0,  1,  2,  3,  2,  1,  0,  0,		\
		    0,  0,  0,  1,  2,  2,  2,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    1,  1,  0,  0,  0,  0,  0,  0,  0,  0,		\
		    2,  1,  0,  0,  0,  0,  0,  0,  0,  0};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img;					\
  FLGR_Ret ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
  ret=flgr2d_distance(img,imgsrc,FLGR_8_CONNEX);				\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
									\
  return 1

int testdistance_fgUINT8(void) {
  tstDistance(fgUINT8);
}
int testdistance_fgUINT16(void) {
  tstDistance(fgUINT16);
}
int testdistance_fgUINT32(void) {
  tstDistance(fgUINT32);
}
int testdistance_fgINT8(void) {
  tstDistance(fgINT8);
}
int testdistance_fgINT16(void) {
  tstDistance(fgINT16);
}
int testdistance_fgINT32(void) {
  tstDistance(fgINT32);
}
int testdistance_fgFLOAT32(void) {
  tstDistance(fgFLOAT32);
}
int testdistance_fgFLOAT64(void) {
  tstDistance(fgFLOAT64);
}

